65
Explore Your Deductive Logic—Sudoku
65
STEP 22 Continued (fill emptycells)
For i = 1 To 9
If sbox(i, j) = putnumber Then numberfound = 1
Next i
If numberfound = 0 Then
notahomecount = 0
For i = 1 To 9
notahome = 0
If sbox(i, j) <> ““ Then notahome = 1
For k = 1 To 9
If cantbelist(i, j, k) = putnumber Then notahome = 1
Next k
If notahome = 1 Then
notahomecount = notahomecount + 1
Else
home = i
End If
Next i
If notahomecount = 8 Then
sbox(home, j) = putnumber
Call updatecantbelist(putnumber, home, j)
Cells(home, j) = sbox(home, j)
End If
End If
Next j
‘ now check all cells in the 3x3 boxes for all numbers 1-9 (putnumber)
‘ if the number is invalid in 8 of the nine cells in the same 3x3 box, then the number
‘ must belong to the ninth cell (empty, of course)
For i = 1 To 3
For j = 1 To 3
For k = 1 To 3
n = Int((i - 1) / 3) * 3 + k
For l = 1 To 3
p = Int((j - 1) / 3) * 3 + l
numberfound = 0
If sbox(n, p) = putnumber Then numberfound = 1
Next l
Next k
If numberfound = 0 Then
notahomecount = 0
For k = 1 To 3
n = Int((i - 1) / 3) * 3 + k
For l = 1 To 3
p = Int((j - 1) / 3) * 3 + l
notahome = 0